﻿using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using NH.Business.Implementations;
using NH.Business.Interfaces;
using NH.Web.AjaxServices.Contracts;

namespace NH.Web.AjaxServices
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(Name = "DepartmentsService", Namespace = "")]
    public class DepartmentsService
    {
        private readonly IDepartmentBusiness _departmentBusiness;

        public DepartmentsService()
        {
            _departmentBusiness = new DepartmentBusiness();
        }

        [OperationContract]
        public DepartmentsContract GetDepartments()
        {
            var results = new DepartmentsContract();
            var listOfDepartments = _departmentBusiness.GetDepartments();

            results.Departments = listOfDepartments.Select(x => new KeyValueContract
                                                                 {
                                                                     Key = x.Id.ToString(),
                                                                     Value = x.Name
                                                                 }).ToArray();

            
            return results;
        }
    }
}
